package com.wjc.wiki.controller;

import com.wjc.wiki.entity.Demo;
import com.wjc.wiki.service.DemoService;
import com.wjc.wiki.service.EbookService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

@RestController
public class TestController {
    @Resource
    private DemoService demoService;
    @Resource
    private EbookService ebookService;

    @Resource
    private RedisTemplate redisTemplate;

    private static final Logger LOG= LoggerFactory.getLogger(WikiuserController.class);


    @Value("${test.hello:TEST}")
    private String testHello;

    @RequestMapping("/hello")
    public String hello(){
        return "hello"+testHello;
    }

    @PostMapping("/hello/post")
    public String helloPost(String name){
        return "hello,Post"+name;
    }

    @GetMapping("/demo/list")
    public List<Demo> list(){
        return demoService.list();
    }

//    @GetMapping("/ebook/list")
//    public List<Ebook> getList(){
//        return ebookService.list();
//    }

    @RequestMapping("/redis/get/{key}")
    public Object get(@PathVariable Long key){
        Object object=redisTemplate.opsForValue().get(key);
        LOG.info("key:{},value:{}",key,object);
        return object;
}

    @RequestMapping("/redis/set/{key}/{value}")
    public String set(@PathVariable Long key,@PathVariable String value){
        redisTemplate.opsForValue().set(key,value,3600, TimeUnit.SECONDS);
        LOG.info("key:{},value:{}",key,value);
        return "Success";
    }

}
